#ifndef __pcap_output__
#define __pcap_output__ 1
#include "sys.h"
#include "packet.h"

enum{
    PCAP_OUTPUT_ERR_NONE = 0,
    PCAP_OUTPUT_ERR_MAX_SIZE,
    PCAP_OUTPUT_ERR_MAX_COUNT,
};

typedef struct {
    int enable;
    int sync;
    FILE* fp;
    char output_file[256];
    int pkt_count;
    int file_max_size;

    int cur_size;
    int cur_count;
    pthread_mutex_t lock;
} pcap_output_t;
#define pcap_output_lock_init(pout) pthread_mutex_init(&pout->lock, NULL)
#define pcap_output_lock(pout)      pthread_mutex_lock(&pout->lock)
#define pcap_output_unlock(pout)    pthread_mutex_unlock(&pout->lock)

extern pcap_output_t* pcap_output_new(char* filename, int max_size, int count);
extern int pcap_output(pcap_output_t* pout, Packet_t* packet);
extern void pcap_output_finish(pcap_output_t* pout);
extern void pcap_set_disable(pcap_output_t* pout);
extern void pcap_set_sync(pcap_output_t* pout);
#endif